package com.yfz.day06;

import java.util.HashMap;

/**
 * 3. 无重复字符的最长子串
 */
class Solution {
    public int lengthOfLongestSubstring(String s) {
        int len =s.length();
        HashMap <Character,Integer>map = new HashMap<>();
        int start = 0;
        int max = 0 ;
        int sum = 0;
        for(int end = 0 ;end< len ;end++)
        {
            char i = s.charAt(end);

            if(map.containsKey(i) && map.get(i) >= start)
            {
                start = map.get(i) + 1 ;
            }
            max =Math.max(max,end - start + 1);
            map.put(i,end);
        }
        return max;
    }
}